<template>
  <div>
    <el-dialog title="考试详情" :modal-append-to-body="false" :visible.sync="visible">
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        style="width: 100%;margin-top: 20px"
      >
        <el-table-column align="center" header-align="center" prop="name" label="考试名称"></el-table-column>
        <el-table-column align="center" header-align="center" prop="passMark" label="及格分数"></el-table-column>
        <el-table-column align="score" header-align="center" prop="passMark" label="总分"></el-table-column>
        <el-table-column prop="isPass" header-align="center" align="center" label="是否及格">
          <template slot-scope="scope">
            <span v-if="scope.row.isPass == 0">未及格</span>
            <span v-if="scope.row.isPass == 1">已及格</span>
          </template>
        </el-table-column>
        <el-table-column prop="isFinish" header-align="center" align="center" label="是否及格">
          <template slot-scope="scope">
            <span v-if="scope.row.isFinish == 0">未完成</span>
            <span v-if="scope.row.isFinish == 1">已完成</span>
          </template>
        </el-table-column>
        <el-table-column prop="submitPaperTime" header-align="center" align="center" label="完成时间"></el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
      ></el-pagination>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="visible = false" :loading="loading">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      dataListLoading: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataList: [],
      records: [],
      dataForm: {
        courseId: '',
        id: ''
      },
      loading: false
    }
  },
  methods: {
    getDataList() {
      this.dataListLoading = true
      this.$nextTick(() => {
        this.$http({
          url: this.$http.adornUrl(
            `/train-admin/courseManage/userCourseExamInfo`
          ),
          method: 'post',
          data: {
            courseId: this.dataForm.courseId,
            userId: this.dataForm.userId
          }
        }).then(res => {
          console.log(res)
          this.dataList = res.data
          this.dataListLoading = false
        })
      })
    },
    init(id, courseId) {
      console.log('........')
      console.log(id)
      this.dataForm.courseId = courseId || 0
      this.dataForm.userId = id
      this.visible = true
      this.getDataList()
    },
    examine(id, checkStatus) {
      this.examVisible = true
      this.$nextTick(() => {
        this.$refs.exam.init(id, checkStatus)
      })
    },
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    }
  }
}
</script>

<style scoped>
</style>
